unit _Tcamera;

interface
 uses
  direct3D9,D3DX9,DXTypes,Config,MyTypes;

 type

Tcamera = Class



 public

  constructor Create(StartPosXY: TPosXY);

  function GetMatView: D3DMATRIX;
//  function PickingProj(MousePos: TposXY ):TposXY;

  procedure MoveUp;
  procedure MoveDown;
  procedure MoveRight;
  procedure MoveLeft;
  procedure ZoomIn;
  Procedure ZoomOut;
  Procedure RotateTrigo;
  Procedure RotateAntiTrigo;

 private

  x,y,z: single;
  a,b:single;

  procedure North;
  procedure South;
  procedure West;
  procedure East;




 end;

implementation




////////////////////////////////////////////////////////////////////////////////
// Public
////////////////////////////////////////////////////////////////////////////////

constructor Tcamera.Create(StartPosXY: TPosXY);
begin

 x:= StartPosXY.x;
 y:= StartPosXY.y;
 z:= 25;

 a:=  0;
 b:= -CameraGap;
end;

function  Tcamera.GetMatView :D3Dmatrix;
begin
 D3DXMatrixLookAtLH(Result,
                    D3DXVector3( x+a, z , y+b ),
                    D3DXVector3(  x , 0 ,  y  ),
                    D3DXVector3(  0 , 1 ,  0  ));
end;

procedure Tcamera.MoveUp;
begin
 if a = 0 then
   if b < 0 then North()
    else South()
 else
   if a > 0 then West()
   else East()
 end;
procedure Tcamera.MoveDown;
begin
 if a = 0 then
   if b < 0 then South()
   else North()
 else
   if a > 0 then East()
   else West()
end;
procedure Tcamera.MoveRight;
begin
 if a = 0 then
   if b < 0 then East()
   else West()
 else
   if a > 0 then North()
   else South()
end;
procedure Tcamera.MoveLeft;
begin
 if a = 0 then
   if b < 0 then West()
   else East()
 else
   if a > 0 then South()
   else North()
end;
procedure Tcamera.ZoomIn;
begin
 if z > 8 then
  z:= z-1
end;
Procedure TCamera.ZoomOut;
begin
 if z < 75 then
  z:= z+1;
end;
Procedure Tcamera.RotateTrigo;
begin
 if b <> 0 then begin
  a:= b;
  b:= 0;
 end else begin
  b:= -a;
  a:= 0;
 end;

end;
Procedure Tcamera.RotateAntiTrigo;
begin
 if a <> 0 then begin
  b:= a;
  a:= 0;
 end else begin
  a:= -b;
  b:= 0;
 end;
end;





////////////////////////////////////////////////////////////////////////////////
// Private
////////////////////////////////////////////////////////////////////////////////

procedure Tcamera.North;
begin
 if y < 2.5*mapsize then
  y:= y + Camerasensitivity;
end;
procedure Tcamera.South;
begin
 if y > -2.5*mapsize then
  y:= y - Camerasensitivity;
end;
procedure Tcamera.West;
begin
 if x > -2.5*mapsize then
  x:= x - Camerasensitivity;
end;
procedure Tcamera.East;
begin
 if x < 2.5*mapsize  then
  x:=x + Camerasensitivity;
end;


end.
